﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Data;
using System.Data.OleDb;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

    public WebService () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }

    [WebMethod]
    public DataSet listaNaigraci()
    {
         System.Data.OleDb.OleDbConnection konekcija = new System.Data.OleDb.OleDbConnection();
    // TODO: Modify the connection string and include any
    // additional required properties for your database.
    
        konekcija.ConnectionString = ConfigurationManager.ConnectionStrings["mojaKonekcija"].ConnectionString;
    
        string sqlBaranje = "SELECT * FROM Player";
        
        OleDbCommand komanda = new OleDbCommand(sqlBaranje, konekcija);
        OleDbDataAdapter adapter = new OleDbDataAdapter(komanda);
        DataSet ds = new DataSet();
        try
        {
            konekcija.Open();
            adapter.Fill(ds, "Player");
        }

        catch (Exception error)
        {
           
        }

    
        finally 
        {
            konekcija.Close();

        }

        return ds;
    }

    [WebMethod]
    public String Minimum()
    {
        System.Data.OleDb.OleDbConnection konekcija = new System.Data.OleDb.OleDbConnection();
        // TODO: Modify the connection string and include any
        // additional required properties for your database.

        konekcija.ConnectionString = ConfigurationManager.ConnectionStrings["mojaKonekcija"].ConnectionString;

        string sqlBaranje = "SELECT MIN(suma) FROM (SELECT SUM(PlayerAmount) as suma FROM Transactions GROUP BY PlayerId)";
                             

        OleDbCommand komanda = new OleDbCommand(sqlBaranje, konekcija);
        OleDbDataAdapter adapter = new OleDbDataAdapter(komanda);
        DataSet ds = new DataSet();
        try
        {
            konekcija.Open();
            adapter.Fill(ds, "Transactions");
        }

        catch (Exception error)
        {

        }


        finally
        {
            konekcija.Close();

        }
        DataRow dr = ds.Tables[0].Rows[0];
       ;
       return dr[0].ToString();
       
    }

    [WebMethod]
    public String Maximum()
    {
        System.Data.OleDb.OleDbConnection konekcija = new System.Data.OleDb.OleDbConnection();
        // TODO: Modify the connection string and include any
        // additional required properties for your database.

        konekcija.ConnectionString = ConfigurationManager.ConnectionStrings["mojaKonekcija"].ConnectionString;

        string sqlBaranje = "SELECT MAX(suma) FROM (SELECT SUM(PlayerAmount) as suma FROM Transactions GROUP BY PlayerId)";


        OleDbCommand komanda = new OleDbCommand(sqlBaranje, konekcija);
        OleDbDataAdapter adapter = new OleDbDataAdapter(komanda);
        DataSet ds = new DataSet();
        try
        {
            konekcija.Open();
            adapter.Fill(ds, "Transactions");
        }

        catch (Exception error)
        {

        }


        finally
        {
            konekcija.Close();

        }
          DataRow dr = ds.Tables[0].Rows[0];
        ;
         return dr[0].ToString();
    }

    [WebMethod]
    public DataSet TransakciiNaigrac(String id)
    {
        System.Data.OleDb.OleDbConnection konekcija = new System.Data.OleDb.OleDbConnection();
        // TODO: Modify the connection string and include any
        // additional required properties for your database.

        konekcija.ConnectionString = ConfigurationManager.ConnectionStrings["mojaKonekcija"].ConnectionString;

        string sqlBaranje = "SELECT * FROM Transactions WHERE PlayerId ="+id;

        OleDbCommand komanda = new OleDbCommand(sqlBaranje, konekcija);
        OleDbDataAdapter adapter = new OleDbDataAdapter(komanda);
        DataSet ds = new DataSet();
        try
        {
            konekcija.Open();
            adapter.Fill(ds, "Transactions");
        }

        catch (Exception error)
        {

        }
        finally
        {
            konekcija.Close();
        }

        return ds;
    }
}
   
   

    

